package com.innovation.chengzhangriji.ui.widget;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.innovation.chengzhangriji.Config;
import com.innovation.chengzhangriji.R;
import com.innovation.chengzhangriji.ui.HeadCameraActivity;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.io.File;
import java.util.ArrayList;

public class HeadPhotosAdapter extends RecyclerView.Adapter<HeadPictureViewHolder> implements HeadPictureViewHolder.OpenPictureListener {

    private Context mContext;

    private ArrayList<String> mArrayList;

    private DisplayImageOptions options; //配置图片加载及显示选项

    public HeadPhotosAdapter(Context context) {
        mContext = context;
        mArrayList = new ArrayList<String>();
    }

    public HeadPictureViewHolder.OpenPictureListener getOpenPictureListener() {
        return openPictureListener;
    }

    public void setOpenPictureListener(HeadPictureViewHolder.OpenPictureListener openPictureListener) {
        this.openPictureListener = openPictureListener;
    }

    private  HeadPictureViewHolder.OpenPictureListener openPictureListener;

    @Override
    public HeadPictureViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_head_picture, viewGroup, false);
        HeadPictureViewHolder viewHolder = new HeadPictureViewHolder(mContext, view);
        viewHolder.setOpenPictureListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(HeadPictureViewHolder holder, int position) {
        ImageLoader.getInstance().displayImage("file://" + mArrayList.get(position), holder.getPicture(), options, null);
    }

    @Override
    public int getItemCount() {
        if (mArrayList != null) {
            return mArrayList.size();
        }
        return 0;
    }

    @Override
    public void openPicture(int position) {
        // resultPath(mArrayList.get(position));
        if(openPictureListener != null) {
            openPictureListener.openPicture(position);
        }
    }

    public void setContent(ArrayList<String> imageUrlList) {
        mArrayList = imageUrlList;
    }

    public void addImageUrl(String imageUrl) {
        mArrayList.add(imageUrl);
    }

    public String getImageUrl(int position) {
        return mArrayList.get(position);
    }
}
